


import store from '@/store'
import moment from 'moment'
export function AddWatermarkHandle (watermark,docRef,docId) {
    //console.log('添加水印啊')
    let watermarkText = watermark?watermark:store.getters.userInfo.realname+moment().format('YYYY年MM月DD日')
    let watermarkDiv = docId?document.getElementById(docId):(docRef?this.$refs[docRef]:this.$refs.wholeWatermarkRef)
    if(watermarkDiv){
        const canvas =document.createElement('canvas');
        canvas.width =200;
        canvas.height =220;
        const ctx = canvas.getContext('2d');
        ctx.rotate(-(Math.PI /4));
        ctx.font ='15px Arial';
        ctx.fillStyle='rgba(0,0,0,.2)';
        ctx.textAlign='center'
        ctx.textBaseline='middle';
        ctx.fillText(watermarkText,canvas.width/12,canvas.height/2.1);
        watermarkDiv.style.backgroundImage =`url(${canvas.toDataURL('image/png')})`;
        watermarkDiv.style.pointerEvents='none';
        watermarkDiv.style.position='absolute';
        watermarkDiv.style.top=0;
        watermarkDiv.style.left =0;
        watermarkDiv.style.width='100%';
        watermarkDiv.style.height='100%'
        watermarkDiv.style.zIndex=999;
    }else{
        //console.log('无法获取到加水印的盒子')
    }
}